<template>
	<view class="verification-detail" :class="themeName">
		<view class="order-contain">
			<view class="order-item-box">
				<view class="order">
					<!-- Order Header -->
					<view class="order-header">
						<view class="order-sn">{{$zhTran('联系人')}}: {{ orderInfo.contact }}</view>
						<view :class="['order-status', 'order-status--primary']">
							{{ orderInfo.verification_status_desc }}
						</view>
					</view>

					<!-- Order Main -->
					<view class="order-main">
						<goods-card v-for="(goodsItem, goodsIndex) in orderInfo.order_goods" :key="goodsIndex"
							shape="rectangle" :name="goodsItem.goods_name" :image="goodsItem.goods_image"
							:contain-style="{ 'border-raius': 0, 'height': '230rpx' }"
							:image-style="{ 'width': '180rpx', 'height': '180rpx' }">
							<view class="m-t-10 order-main__spec">
								<text class="muted xs">{{ goodsItem.spec_value_str }}</text>
								<text class="lighter sm">x{{ goodsItem.goods_num }}</text>
							</view>
						</goods-card>
					</view>
				</view>

				<view class="operation operation--primary" @click="showVerificationModal = true">{{$zhTran('已提货')}}
				</view>
				<view class="operation operation--normal" @click="goVerificationList">{{$zhTran('返回核销列表')}}</view>
			</view>
			<w-jishuzhichi class="jishuzhichi-nodata" />
		</view>

		<!-- 二次确认核销 -->
		<u-modal ref="uModalInput" v-model="showVerificationModal" show-cancel-button :confirm-color="themeColor"
			:confirm-text="$zhTran('确定')" :title="$zhTran('确认核销')" :content="$zhTran('是否确认核销？')"
			@confirm="handleVerificationConfirm" />

		<!-- 页面状态 -->
		<page-status :status="pageStatus">
			<view slot="error" class="flex-col column-center">
				<u-empty :text="$zhTran('订单异常')" :src="$getImageUri('resource/image/shopapi/uniapp/empty/order.png')"
					:icon-size="280"></u-empty>
				<view class="operation operation--primary" @click="goVerificationList">{{$zhTran('返回核销列表')}}</view>
			</view>
		</page-status>
	</view>
</template>


<script>
	import {
		apiVerificationOrderDetail,
		apiVerificationOrderConfirm
	} from '@/api/order'
	import {
		PageStatusEnum
	} from '@/utils/enum'

	export default {
		name: 'VerificationDetail',

		data() {
			return {
				code: '', // 核销码
				orderInfo: {}, // 订单信息
				pageStatus: PageStatusEnum['LOADING'],
				showVerificationModal: false, // 显示(核销)：是|否
			}
		},

		methods: {
			// 初始化订单数据
			initOrderData() {
				return new Promise((resolve, reject) => {
					apiVerificationOrderDetail({
						pickup_code: this.code,
					}).then(data => {
						this.orderInfo = this.$zhTran(data)
						resolve(data)
					}).catch(err => {
						reject(err.message)
					})
				})
			},

			// 确认核销订单
			handleVerificationConfirm() {
				apiVerificationOrderConfirm({
					id: this.orderInfo.id
				}).then(data => {
					// this.initOrderData()
					setTimeout(() => {
						this.$Router.back()
					}, 0.5 * 1000)
				})
			},

			// 返回核销列表
			goVerificationList() {
				this.$Router.back()
			}
		},

		async onLoad() {
			const options = this.$Route.query
			if (this.$Route.meta.atitle) {
				uni.setNavigationBarTitle({
					title: this.$zhTran(this.$Route.meta.atitle)
				})
			}

			try {
				if (!options.code) throw new Error(this.$zhTran('订单异常'))
				this.code = options.code
				await this.initOrderData()
				console.log("HELLOW")
				this.pageStatus = PageStatusEnum['NORMAL']
			} catch (err) {
				console.log(err)
				// setTimeout(() => {
				// 	this.$Router.back()
				// }, 0.5 * 1000)
				this.pageStatus = PageStatusEnum['ERROR']
			}
		}

	}
</script>


<style lang="scss" scoped>
	page {
		height: 100%;
		padding: 0;
	}

	.verification-detail {
		padding: 0 20rpx;
		height: 100%;
		display: flex;
		flex-direction: column;

		.order-contain {
			flex: 1;
			min-height: 0;

			.order-item-box {
				height: calc(100% - constant(safe-area-inset-bottom));
				height: calc(100% - env(safe-area-inset-bottom));
			}
		}
	}

	.order {
		padding-left: 20rpx;
		margin-top: 20rpx;
		border-radius: 5px;
		background-color: #FFFFFF;

		&-header {
			display: flex;
			height: 80rpx;
			align-items: center;
			padding-right: 20rpx;
			border-bottom: $-dashed-border;

			.order-sn {
				font-size: $-font-size-nr;
			}

			.order-status {
				margin-left: auto;
				font-size: $-font-size-sm;

				&--primary {
					@include font_color()
				}

				&--muted {
					color: $-color-muted;
				}
			}
		}

		&-main {
			&__spec {
				display: flex;
				justify-content: space-between;
				height: 100%;
			}
		}
	}

	.operation {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 80rpx;
		margin-top: 20rpx;
		border-radius: 60px;

		&--primary {
			@include background_color() color: #FFFFFF;
		}

		&--normal {
			background-color: #FFFFFF;
			color: $-color-normal;
		}
	}
</style>